#ifndef MAINWINDOWIMPL_H
#define MAINWINDOWIMPL_H
//
#include "ui_mainwindow.h"
#include "ui_config.h"
#include "ui_edit.h"

#include "smppstack.h"
#include "msgfactory.h"
#include "highlighter.h"

//
class MainWindowImpl : public QMainWindow, public Ui::MainWindow
{
Q_OBJECT
public:
	MainWindowImpl( QWidget * parent = 0, Qt::WFlags f = 0 );
	void writeSettings();
	void readSettings();
	void readSettingsFromConfig();
	void closeEvent(QCloseEvent *event);
	
protected:
	void createToolBox();
	QWidget *createCellWidget(QButtonGroup *group, int id, const QString &text, const QString &image);

	QButtonGroup* messageButtonGroup;
    QButtonGroup *timerButtonGroup;

	int selectedId;
	QString selectedButtonString;
	
	MsgFactory msgfactory;
	int curmsgIndex;
	
    Highlighter *highlighter;
	
private slots:
	void messageButtonGroupClicked(int id);
	void timerButtonGroupClicked(QAbstractButton *button);
	
	void listWidgetClicked(QListWidgetItem *item);
	void showItemEditDialog(QListWidgetItem *item);

	void on_actionAdd_triggered();
	void on_actionRemove_triggered();
	void on_actionInsert_triggered();
	void on_actionClear_triggered();
	void on_actionOpen_triggered();
	void on_actionSave_triggered();
	
	void on_actionExecute_triggered();
	void on_actionStop_triggered();
	void nextStep();
	
	void sendMsg();
	void startsend();
	void conn();
	void disconn();
	void notifyLink_active();
	void notifyLink_break();
	void showConfigDialog();
	void setRecvContent(QString content);

	void showSend(int type, void *ptr);
	void showRecv(int type, QByteArray buff);
	void showmsgdetail(int row, int column);
	
private:
	SmppBase *smpplink;
	QTimer *timer;
	QTimer *timersend;
    QList<QTextCodec *> codecs;
	QString encodeStr;
    QByteArray encodedData;
    QString decodedStr;

	//QToolButton *statusImage;
	//QLabel *statusLabel;

};

class CConfig : public QDialog, public Ui::Config
{
Q_OBJECT
public:
	CConfig(QWidget * parent = 0, Qt::WFlags f = 0 );
	void writeSettings();
	void readSettings();
	void closeEvent(QCloseEvent *event);
private slots:
	void setMsg();
};

class ScheduleData : public QObject
{
Q_OBJECT
public:
	enum ACTION_TYPE {ACTION_NONE=0,ACTION_SEND,ACTION_RECV,ACTION_DELAY,ACTION_TIMEOUT};

	ACTION_TYPE type;
	unsigned int id;
	QString data;

};

class CEdit : public QDialog, public Ui::Edit
{
Q_OBJECT
public:
	CEdit(int *actiontype, QString *content, QWidget * parent = 0, Qt::WFlags f = 0 );
	static int get(QWidget *parent, int *actiontype, QString *content);
private slots:
	void set();
	void on_toolButton_open_clicked();
	void on_toolButton_save_clicked();
private:
	int     *pactiontype;
	QString *pcontent;

    Highlighter *highlighter;
};


class MyTableWidgetItem : public QTableWidgetItem	
{
public:
	MyTableWidgetItem(QString str):QTableWidgetItem(str){}

	unsigned int id;
	void *data;

};

#endif





